import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDPlantInfo {
	/**ID*/
	id,
	/**名字*/
	name,
	/**描述*/
	desc,
	/**成长值*/
	growTarget,
	/**浇水最低成长值*/
	minGrowth,
	/**浇水最高成长值*/
	maxGrowth,
	/**每次浇水时获得的奖励*/
	dropid,
	/**成长值满时奖励的物品ID*/
	dropid2,
	/**刷新时下一棵树是它的概率（万分）*/
	rateNext,

	/**枚举数量*/
	EnumCount
}



export class CDPlantInfo{
	/**ID*/
	public id: number;
	/**名字*/
	public name: number;
	/**描述*/
	public desc: number;
	/**成长值*/
	public growTarget: number;
	/**浇水最低成长值*/
	public minGrowth: number;
	/**浇水最高成长值*/
	public maxGrowth: number;
	/**每次浇水时获得的奖励*/
	public dropid: number;
	/**成长值满时奖励的物品ID*/
	public dropid2: number;
	/**刷新时下一棵树是它的概率（万分）*/
	public rateNext: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDPlantInfo.id: return this.id;
			case E_CDPlantInfo.name: return this.name;
			case E_CDPlantInfo.desc: return this.desc;
			case E_CDPlantInfo.growTarget: return this.growTarget;
			case E_CDPlantInfo.minGrowth: return this.minGrowth;
			case E_CDPlantInfo.maxGrowth: return this.maxGrowth;
			case E_CDPlantInfo.dropid: return this.dropid;
			case E_CDPlantInfo.dropid2: return this.dropid2;
			case E_CDPlantInfo.rateNext: return this.rateNext;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDPlantInfo.id: this.id = v; break;
			case E_CDPlantInfo.name: this.name = v; break;
			case E_CDPlantInfo.desc: this.desc = v; break;
			case E_CDPlantInfo.growTarget: this.growTarget = v; break;
			case E_CDPlantInfo.minGrowth: this.minGrowth = v; break;
			case E_CDPlantInfo.maxGrowth: this.maxGrowth = v; break;
			case E_CDPlantInfo.dropid: this.dropid = v; break;
			case E_CDPlantInfo.dropid2: this.dropid2 = v; break;
			case E_CDPlantInfo.rateNext: this.rateNext = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDPlantInfo> = new HashMap<number, CDPlantInfo>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDPlantInfo[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDPlantInfo();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].growTarget = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].minGrowth = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].maxGrowth = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].dropid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].dropid2 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rateNext = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDPlantInfo{
		return this.datas ? this.datas.get(id) : null;
	}
}
